/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.scm.rmpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author Kenn
 */
@Entity
public class GoodsReceipt implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String goodsReceiptId;
    private Double actualLeadTime;
    private Timestamp dateReceipt;
    @ManyToOne(targetEntity = Supplier.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private Supplier supplier;
    @OneToOne(targetEntity = RawMaterialSalesOrder.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER, mappedBy = "goodsReceipt")
    private RawMaterialSalesOrder rmso;
    @OneToMany(targetEntity = RawMaterialItemLine.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private Collection<RawMaterialItemLine> itemlines;
    @OneToOne(targetEntity = GoodsReceiptRating.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private GoodsReceiptRating rating;

    public GoodsReceipt() {
        dateReceipt = new Timestamp(System.currentTimeMillis());
        supplier = null;
        rmso = null;
        itemlines = new ArrayList<RawMaterialItemLine>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getGoodsReceiptId() {
        return goodsReceiptId;
    }

    public void setGoodsReceiptId(String goodsReceiptId) {
        this.goodsReceiptId = goodsReceiptId;
    }

    public Timestamp getDateReceipt() {
        return dateReceipt;
    }

    public void setDateReceipt(Timestamp dateReceipt) {
        this.dateReceipt = dateReceipt;
    }

    public Collection<RawMaterialItemLine> getItemlines() {
        return itemlines;
    }

    public void setItemlines(Collection<RawMaterialItemLine> itemlines) {
        this.itemlines = itemlines;
    }

    public RawMaterialSalesOrder getRmso() {
        return rmso;
    }

    public void setRmso(RawMaterialSalesOrder rmso) {
        this.rmso = rmso;
    }

    public Supplier getSupplier() {
        return supplier;
    }

    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    public GoodsReceiptRating getRating() {
        return rating;
    }

    public void setRating(GoodsReceiptRating rating) {
        this.rating = rating;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GoodsReceipt)) {
            return false;
        }
        GoodsReceipt other = (GoodsReceipt) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.scm.rmpm.entity.GoodsReceipt[ id=" + id + " ]";
    }

    /**
     * @return the actualLeadTime
     */
    public Double getActualLeadTime() {
        return actualLeadTime;
    }

    /**
     * @param actualLeadTime the actualLeadTime to set
     */
    public void setActualLeadTime(Double actualLeadTime) {
        this.actualLeadTime = actualLeadTime;
    }
}
